 # -*- coding: UTF-8 -*-


import os
import stat
import sendReq
import getImg
from bs4 import BeautifulSoup
import time

def getImgUrl(html):
	soup = BeautifulSoup(html)
	l = []
	divs = soup.find_all('div', class_='text')
	for d in divs:
		s = ''
		try:
			s = d.p.img['src']
			#pass
		except Exception, e:
			#raise
			pass
		else:
			l.append(s)
			#pass
		finally:
			pass
		
	return l


def reqImgs(imgurls, path):
	for src in imgurls:
		getImg.downImg1(src, path)



p = 'E:\\Temp\\img\\'
os.chdir(p)
#更改权限 
os.chmod(p, stat.S_IRWXU|stat.S_IRWXG|stat.S_IRWXO)

#jiandan.com
url ='http://jandan.net/ooxx/page-{0:d}'
idx = 2131
while idx > 0:
	
	u = url.format(idx)
	print(u)
	c = sendReq.getHtml(u)
	imgs = getImgUrl(c)
	#print(imgs)
	reqImgs(imgs, p)

	print(idx)
	idx -= 1
	time.sleep(1)
